<template>
<el-dialog :title="!payload.order_id? '新建订单' : '订单详情'" :show-close="false" v-model="addOrderDialog" @close="handleRemoveModal(remove)" size="auto" :closeOnClickModal="false">
    <base-input @closedialog="handleClose">
        <el-row slot="body">
            <el-row class="body-top">
                <el-form ref="form" :model="form" label-width="121px" class="add-task-form">
                    <el-form-item label="学员ID">
                        <el-input :disabled='true' v-model="form.student_id" placeholder="请输入学员ID"></el-input>
                    </el-form-item>
                    <el-form-item label="点师成金用户ID">
                        <el-input :disabled='true' v-model="form.student_id" placeholder="请输入学员ID"></el-input>
                    </el-form-item>
                    <!--<el-form-item label="昵称">
                        <el-input v-model="form.code" placeholder="请输入昵称"></el-input>
                    </el-form-item>-->
                    <el-form-item label="姓名" v-if='!payload.order_id?false:true'>
                        <el-input :disabled='true' v-model="form.realname" placeholder="请输入姓名"></el-input>
                    </el-form-item>
                    <el-form-item label="电话" v-if='!payload.order_id?false:true'>
                        <el-input :disabled='true' v-model="form.phone" placeholder="请输入电话"></el-input>
                    </el-form-item>
                    <el-form-item label="邮箱" v-if='!payload.order_id?false:true'>
                        <el-input v-model="form.email" placeholder="请输入邮箱"></el-input>
                    </el-form-item>
                    <el-form-item label="所在院校" v-if='!payload.order_id?false:true'>
                        <el-input v-model="form.school" placeholder="请输入所在院校"></el-input>
                    </el-form-item>
                    <el-form-item label="专业" v-if='!payload.order_id?false:true'>
                        <el-input v-model="form.school_subject" placeholder="请输入专业"></el-input>
                    </el-form-item>
                    <el-form-item label="在读年级" v-if='!payload.order_id?false:true'>
                        <el-input v-model="form.school_grade" placeholder="请输入在读年级"></el-input>
                    </el-form-item>
                    <el-form-item label="所属经销商" v-if='!payload.order_id?false:true'>
                        <el-select :disabled="payload?true:false" v-model="form.dealer_id" placeholder="请选择所属经销商">
                            <el-option v-for="item in dealerList" :key="item.id" :label="item.company" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="所选产品">
                        <el-select :disabled="payload.order_id?true:false" v-model="form.product_id" placeholder="请选择所选产品" @change='changeProduct'>
                            <el-option v-for="item in productList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="产品定价(分)">
                        <el-input-number :disabled="true" placeholder="请输入产品定价" v-model="form.product_price" :min='0'></el-input-number>
                    </el-form-item>
                    <el-form-item label="实收金额（分）">
                        <el-input-number placeholder="请输入实收金额" v-model="form.product_real_pay_price" :min='0'></el-input-number>
                    </el-form-item>
                    <el-form-item label="是否开具发票">
                        <el-row class='row-container' type='flex' justify='start' align='middle'>
                        <el-switch
  v-model="form.is_invoice"
  on-text="已开"
  off-text="未开"
  :width='75'>
</el-switch>  
                        </el-row>
                    </el-form-item>
                    <el-form-item v-if='!payload.order_id?false:true' label="订单编号">
                        <el-input :disabled='true' v-model="form.guid" placeholder="请输入订单编号"></el-input>
                    </el-form-item>
                    <el-form-item v-if='!payload.order_id?false:true' label="订单状态">   
                        <el-select :disabled='true' v-model="form.state" placeholder="请选择经销商类别">
                            <el-option v-for="item in stateList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                        </el-select>                    
                    </el-form-item>
                    <el-form-item label="订单类型">
                        <el-select v-model="form.type" placeholder="请选择订单类别">
                            <el-option v-for="item in typeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="学段" v-if='!payload.order_id?false:true'>
                        <el-select v-model="form.subject_id" placeholder="请选择学段">
                            <el-option v-for="item in subjectList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="学科" v-if='!payload.order_id?false:true'>
                           <el-select v-model="form.grade_id" placeholder="请选择学科">
                            <el-option v-for="item in gradeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="学期">
                        <el-input v-model="form.term" placeholder="请输入学期"></el-input>
                    </el-form-item>
                    <el-form-item label="开课时间">
                                <el-date-picker v-model="form.start_school_time" type="date" placeholder="请选择开课时间">
                                </el-date-picker>
                    </el-form-item>
                    <el-form-item label="毕业时间">
                                <el-date-picker v-model="form.finish_school_time" type="date" placeholder="请选择毕业时间">
                                </el-date-picker>
                    </el-form-item>
                    <el-form-item label="离校时间">
                                <el-date-picker v-model="form.leave_school_time" type="date" placeholder="请选择离校时间">
                                </el-date-picker>
                    </el-form-item>
                    <el-form-item label="就业去向">
                        <el-input v-model="form.employment" placeholder="请输入就业去向"></el-input>
                    </el-form-item>
                     <el-form-item label="导师">
                        <el-input v-model="form.tutor" placeholder="请输入导师"></el-input>
                    </el-form-item>
                     <el-form-item label="学管">
                        <el-input v-model="form.xg" placeholder="请输入学管"></el-input>
                    </el-form-item>
                    <!--<el-form-item label="特殊类型">
                        <el-select v-model="form.product_id" placeholder="请选择特殊类型">
                            <el-option v-for="item in productionList" :key="item.id" :label="item.title" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>-->
                    <el-form-item label="备注">
                        <el-input v-model="form.more" placeholder="请输入备注"></el-input>
                    </el-form-item>
                                        <el-form-item class="btns">
                        <el-button class="btn-orange" @click="handleSubmit" v-if='!payload.order_id'>保存</el-button>
                    </el-form-item>
                </el-form>
            </el-row>
        </el-row>
    </base-input>
</el-dialog>
</template>
<!-- task_id = 19 -->
<script>
import BaseInput from '../../components/BaseInput'
import UploadPanel from '../../components/UploadPanel'
import Editor from '../../components/Editor'
import BaseList from '../../components/BaseList'
import { Loading } from 'element-ui'
import { Config } from '../../config/base'
import {
    RemoveModal
} from './mixins'
import {
    mapActions,
    mapState,
    mapGetters
} from 'vuex';
import {
    getDetail
} from '../../api/modules/order'
import dateFormat from '../../config/dateFormat'
    import {
    MPop
} from '../../components/MessagePop'
export default {
    mixins: [RemoveModal,MPop],
    props: {
        remove: {
            type: String
        },
        payload: {}
    },
    data() {
        return {
            addOrderDialog: true,
            form: {
                order_id:0,
                guid:'',
                dscj_user_id:0,
                student_id:0,
                product_id:null,
                product_real_pay_price:0,
                is_invoice:false,
                type:null,
                term:'',
                h5_url:'',
                start_school_time:null,
                finish_school_time:null,
                leave_school_time:null,
                employment:'',
                tutor:'',
                xg:'',
                more:'',
                state:0,
                realname:'',
                phone:'',
                email:'',
                school:'',
                school_subject:'',
                school_grade:'',
                dealer_id:null,
                subject_id:null,
                grade_id:null,
                is_regist:false,
                product_name:'',
                product_price:0,
                _fn:null
            },
            loadingInstance:null
        }
    },
    mounted() {
        this.get_agency_selection_list();
        this.get_subject_list();
        this.get_grade_list();
        this.get_product_list();
        this.form.student_id = this.payload.student_id;
        this.form.dscj_user_id = this.payload.dscj_user_id;
        if(this.payload.order_id)
        {
            this.loadingInstance = Loading.service({
                text:'加载中，请稍后',
                    fullscreen: true
                });
                setTimeout(() => {
                    this.loadingInstance.close();
                }, Config.base_timeout);
            getDetail(this.payload.order_id).then(res => {
                if(res.data.res_code === 1)
                {
                    for(var p in res.data.msg)
                    {
                        this.form[p] = res.data.msg[p];
                    }
                    this.form.order_id = this.payload.order_id;
                    this.loadingInstance.close();
                }
            })
        }

        var vm = this;

        this.form.order_id = this.payload;

        this.form._fn = function(){
            vm.handleClose();
            vm.showPop('保存成功！');
        }
    },
    computed: {
        ...mapState({
            stateList: state => state.order.state_list,
            dealerList: state => state.agency.agency_selection_list,
            typeList: state => state.order.type_list,
            subjectList: state => state.subject.subject_list,
            gradeList: state => state.grade.grade_list,
            productList: state => state.product.product_list
        }),
        dataHeader() {
             return [{
                    label:'排序',
                    width:90,
                    sort:true
                }, {
                    prop: 'teacher_name',
                    label: '讲师',
                    width: 150
                }, {
                    prop: 'title',
                    label: '课程名称'
                },  {
                    label: '操作',
                    width: 100,
                    groupBtn: [{
                        text: '',
                        param: 'changeSelect',
                        switchKey:'is_valid',
                        useCheckBox:true
                    }]
                }]
        }
    },
    methods: {
        ...mapActions([
            'add_order',
            'update_order',
            'get_subject_list',
            'get_grade_list',
            'get_agency_selection_list',
            'get_product_list'
        ]),
        changeProduct(val) {
            for(var i=0;i<this.productList.length;i++)
            {
                if(this.productList[i].id === val)
                {
                    this.form.product_price = this.productList[i].price;
                    break;
                }
            }
        },
        handleClose() {
            this.addOrderDialog = false;
        },
        handleSubmit() {
            var arrObj = {
                default:this.form.img_url,
                video:this.form.video_url
            }
            if(this.payload.order_id)
            {
                this.update_order(this.form);
            }
            else
            {
                this.add_order(this.form);
            }
        }
    },
    components: {
        'base-input': BaseInput,
        'upload-panel': UploadPanel,
        'text-editor':Editor,
        'data-list': BaseList,
    },
}
</script>
<style lang="scss">
#add-order-container {
    @import "base.scss";
    input,
    textarea {
        resize: none;
        outline: none;
    }
    .close-dialog-panel {
        position: absolute;
        top: -40px;
        right: 13.5px;
        z-index: 99999;
        font-size: 30px;
        cursor: pointer;
        &:before {
            // color: #fff;
            color: #757575;
        }
    }
    .el-dialog {
        width: 600px;
        background: none;

        .curriculum-list {
            .title {
                padding: 0 20px;
                h2 {
                    font-size: 16px;
                }
            }
            .search-bar {
                padding: 0 20px;
                margin-bottom: 20px;
                .el-button {
                    background: #FB843E;
                    border-radius: 4px;
                    border:0;
                }
            }
        }

        .body-top {
            padding-bottom: 10px;
        }

        .el-dialog__header {
            background: #333333;
            border-radius: 4px 4px 0 0;
            padding: 16px;
        }
        .el-dialog__body {
            padding: 0;
            background: #fff;
            border-radius: 0 0 4px 4px;
        }
        .add-task-form {
            width: 80%;
            margin: 30px auto;
            .el-date-editor--datetimerange,
            .el-select {
                width: 100%;
            }
            input {
                border-radius: 0;
                border: 1px solid #CCCCCC;
            }
            .approval {
                .el-form-item__content {
                    text-align: left;
                    line-height: 38px;
                }
            }
            
            .row-container {
                height:36px;
            }

            .el-date-editor {
                width:100%;
            }
            .el-input-number {
                width: 100%;
            }
            // -------- 修改了单选框样式 ------------

            .el-radio__inner {
                display: inline-block;
                position: relative;
                border: 1px solid #bfcbd9;
                border-radius: 4px;
                box-sizing: border-box;
                width: 18px;
                height: 18px;
                background-color: #fff;
                z-index: 1;
                transition: border-color 0.25s cubic-bezier(.71,-.46,.29,1.46),background-color 0.25s cubic-bezier(.71,-.46,.29,1.46);
                border-color: #979797;
                background-color: transparent;
                &::after {
                    box-sizing: content-box;
                    content: "";
                    border: 2px solid #fff;
                    border-left: 0;
                    border-top: 0;
                    height: 8px;
                    left: 5px;
                    position: absolute;
                    top: 1px;
                    transform: rotate(45deg) scaleY(0);
                    width: 4px;
                    transition: transform 0.15s cubic-bezier(.71,-.46,.88,.6) 0.05s;
                    transform-origin: center;
                    border-radius: 0;
                    background-color: transparent;
                }
            }
            .is-checked {

                .el-radio__label {
                    border: 1px solid #5FA137;
                    color: #5FA137;
                }

                .el-radio__inner {
                    border-color: #5FA137;
                    background-color: #5FA137;
                }
                .el-checkbox__inner {
                    border-color: #5FA137;
                    background-color: #5FA137;
                }
                .el-radio__inner::after {
                    transform: rotate(45deg) scaleY(1);
                }
            }
            // -------- 修改了单选框样式 ------------
            @mixin el-upload-common($w) {
                .el-upload {
                    text-align: left;
                    width: 100%;
                    .el-icon-upload {
                        color: #999999;
                    }
                    .el-upload__tip {
                        font-size: 12px;
                        color: #757575;
                        letter-spacing: 0;
                        line-height: 20px;
                        text-align: left;
                        margin-top: 0;
                    }
                    .el-dragger {
                        // float: left;
                        // width: 240px;
                        border-radius: 0;
                        background-color: #F6F6F6;
                        border: 1px solid #CCCCCC;
                        width: 100%;
                        height: $w;
                        .el-icon-upload {
                            margin-left: 0;
                            // margin-top: $_top;
                        }
                        .el-dragger__text {
                            font-size: 14px;
                            color: #757575;
                            letter-spacing: 0;
                            line-height: 14px;
                            margin-top: 20px;
                        }
                    }
                }
            }
            .upload-form1 {
                @include el-upload-common(200px);
            }
            .check-upload {
                text-align: left;
            }
            .inter-data {
                .el-form-item__label {
                    width: 100px !important;
                }
                .el-form-item__content {
                    margin-left: 102px !important;
                }
            }
            .upload-file-list {
                text-align: left;
                width: 40%;
                .datetime{
                  position: absolute;
                  right: -170px;
                  top: 16px;
                }
                .file-item {
                    cursor: pointer;
                    // padding-top: 6px;
                    // padding-bottom: 6px;
                    // margin-top: 15px;
                    // margin-bottom: 15px;
                    position: relative;

                    &:hover {
                        color: #FB843E;
                    }
                    .filename{
                      width: 150px;
                      overflow: hidden;
                      height: 30px;
                      line-height: 30px;
                      text-overflow: ellipsis;
                      white-space: nowrap;
                      display: inline-block;
                    }
                    .el-icon-delete {
                        position: absolute;
                        right: -20px;
                        top: 10px;
                    }
                }

            }
            .btns {
                margin-top: 50px;
                .el-form-item__content {
                    margin-left: 0 !important;
                    margin-top: 10px !important;
                    line-height: 0;
                    .finish-btn {
                        margin-left: 0;
                        margin-top: 20px;
                        background: #FB843E;
                        border-radius: 4px;
                        width: 160px;
                        height: 36px;
                        border: 0;
                        &:last-child {
                            margin-left: 8px;
                        }
                    }
                    // button {
                    //     width: 100px;
                    //     height: 36px;
                    //     background: #FFFFFF;
                    //     border: 1px solid #999999;
                    //     border-radius: 4px;
                    // }
                }

                .btn-pre {
                    float: left;
                    color:#333333;
                }

                .btn-orange {
                    background: #FB843E;
                    border: 1px solid #F06B1D;
                    border-radius: 4px;
                    color: #fff;
                    width: 200px;
                    height: 36px;
                }
            }
            .el-form-item__content {
                // margin-left: 0 !important;
                line-height: 0;
                .el-textarea {
                    .el-textarea__inner {
                        background: #FFFFFF;
                        border: 1px solid #CCCCCC;
                        // height: 140px;
                        border-radius: 0;
                        // width: 390px;
                    }
                }
                .editor {
                    .vueditor {
                        line-height:100%;
                    }
                }  
            }
        }
    }
}
</style>
